package tw.com.diary.core;

import tw.com.diary.ae.com.DirayBussinessException;
import tw.com.diary.api.com.Contract;
import tw.com.diary.api.domain.UserInfoDTO;
import tw.com.diary.api.service.UserInfoService;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class UserInfoServiceImpl implements UserInfoService {

	@Override
	public void getSource(UserInfoDTO dto, Context context) throws DirayBussinessException {

		final SharedPreferences sp = context.getSharedPreferences(Contract.USER_SETTING, 0);

		dto.setAlertFlag(sp.getBoolean(Contract.IS_ALERT_FLAG, false));
		dto.setEmail(sp.getString(Contract.EMAIL, Contract.BLANK));
		dto.setNickName(sp.getString(Contract.NICKNAME, Contract.BLANK));
		dto.setAlertContent(sp.getString(Contract.ALERT_CONTENT, Contract.BLANK));
		dto.setHour(sp.getString(Contract.ALERT_HOUR, Contract.BLANK));
		dto.setMiniute(sp.getString(Contract.ALERT_MINUTE, Contract.BLANK));

	}

	@Override
	public void saveProperty(UserInfoDTO dto, Context context) throws DirayBussinessException {

		final SharedPreferences sp = context.getSharedPreferences(Contract.USER_SETTING, 0);

		final Editor ed = sp.edit();
		ed.putString(Contract.EMAIL, dto.getEmail());
		ed.putString(Contract.NICKNAME, dto.getNickName());
		ed.putString(Contract.ALERT_CONTENT, dto.getAlertContent());
		ed.putBoolean(Contract.IS_ALERT_FLAG, dto.isAlertFlag());
		ed.putString(Contract.ALERT_HOUR, dto.getHour());
		ed.putString(Contract.ALERT_MINUTE, dto.getMiniute());

		ed.commit();

	}

}
